﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
  <xsl:output method="xml" indent="yes"/>"
  <xsl:template match="@* | node()">
    <xsl:apply-templates select="@* | node()"/>
  </xsl:template>
  <xsl:template match="/statuses">
    <entity source="twitter" crm_entity="msa_snstatus" source_object="statuses">
      <xsl:apply-templates/>
    </entity>
  </xsl:template>
  <xsl:template match="/statuses/status">
    <record crm_id="">
      <attrib crm_name="msa_snfollowers_count" crm_type="CrmNumberProperty">
        <xsl:value-of select="user/followers_count/text()"/>
      </attrib>
      <attrib crm_name="msa_directioncode" crm_type="CrmBooleanProperty">false</attrib>
      <xsl:apply-templates/>
    </record>
  </xsl:template>
  <xsl:template match="/statuses/status/*">
    <xsl:if test="name()='text'">
      <attrib crm_name="msa_text" crm_type="StringProperty">
        <xsl:value-of select="text()"/>
      </attrib>
    </xsl:if>
    <attrib>
      <xsl:attribute name="crm_name">
        msa_sn<xsl:value-of select="name()"/>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="name()='protected' or name()='truncated' or name()='favorited'">
          <xsl:attribute name="crm_type">CrmBooleanProperty</xsl:attribute>
        </xsl:when>
        <xsl:when test="name() = 'created_at'">
          <xsl:attribute name="crm_type">CrmDateTimeProperty</xsl:attribute>
        </xsl:when>
        <xsl:when test="name() = 'followers_count'">
          <xsl:attribute name="crm_type">CrmNumberProperty</xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="crm_type">StringProperty</xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:value-of select="text()"/>
    </attrib>
  </xsl:template>
  <xsl:template match="/statuses/status/user">
    <lookup entity_name="msa_sncontact" search="msa_snid" action="CreateIfAbsent" crm_name="msa_sncontactid">
      <xsl:attribute name ="search_key">
        <xsl:value-of select="child::id/text()"/>
      </xsl:attribute>
      <attrib crm_name="msa_snscreen_name" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::screen_name/text()"/>
      </attrib>
      <attrib crm_name="msa_snid" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::id/text()"/>
      </attrib>
      <attrib crm_name="msa_snlocation" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::location/text()"/>
      </attrib>
      <attrib crm_name="msa_sndescription" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::description/text()"/>
      </attrib>
      <attrib crm_name="msa_snname" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::name/text()"/>
      </attrib>
      <attrib crm_name="msa_snprofile_image_url" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::profile_image_url/text()"/>
      </attrib>
      <attrib crm_name="msa_sncreated_at" crm_type="CrmDateTimeProperty" force_update="false">
        <xsl:value-of select="child::created_at/text()"/>
      </attrib>
      <attrib crm_name="msa_snurl" crm_type="StringProperty" force_update="false">
        <xsl:value-of select="child::url/text()"/>
      </attrib>
      <attrib crm_name="msa_snfollowers_count" crm_type="CrmNumberProperty" force_update="true">
        <xsl:value-of select="child::followers_count/text()"/>
      </attrib>
    </lookup>
  </xsl:template>
</xsl:stylesheet>